$(function(){
	initSortStatus();
	$('[sort-field]').click(function(){
		var field = $(this).attr("sort-field");
		var director = "";
		var currClass = $(this).attr("class");
		if($(this).hasClass('sorting'))
		{
			director = "asc";
		}
		if($(this).hasClass('sorting_asc'))
		{
			director = "desc";
		}
		if($(this).hasClass('sorting_desc'))
		{
			field = "";
			director = "";
		}
		$('#sortField').val(field);
		$('#sortBy').val(director);
		$('#searchForm').submit();
	});
});
function initSortStatus()
{
	var driector = $('#sortBy').val();
	driector = driector && driector != "" ? driector.toLowerCase() : "";
	var currClass = driector;
	var field = $('#sortField').val();
	if(field && field != null && driector && driector != null)
	{
		$('[sort-field='+field+']').
            removeClass("sorting").
            removeClass("sorting_desc").
            removeClass("sorting_asc").
            addClass("sorting_" + currClass);
	}
	
}